﻿using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Linq;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class PileRebar
    {
         double D;
         PileRebarPara pileParameter;
        string strDiameter = "%%130";
        string strMainDiameter = "D";

        double tH =100;
        double th1 = 0;
        double tL =10;
        double bH = 100;
        double bL = 10;
        double N3Dia1 = 0;
        double N3Dia2 = 0;
        double N3Len = 0;
        double N4Dia = 0;
        double N4Len = 0;
        double N5Len = 0;
        int N4 = 0;
        double spiralDia = 0;
        string bridgeId = "";
        bool isAddHT = true;
        bool isExistCap = false;
        double htTh = 16;
        public PileRebar(PileRebarPara para, string _bridgeId = "",bool _isExistCap=true)
        {
            pileParameter = para;
            bridgeId = _bridgeId;
            D = para.pile_diameter;
            if(para.is_add_steel_casing=="0")
                isAddHT = false;
            isExistCap = _isExistCap;
            switch (para.reinforcement_grade)
            {
                case "HRB300":
                    strDiameter = "A";
                    break;
                case "HRB335":
                    strDiameter = "B";
                    break;
                case "HRB400":
                    strDiameter = "C";
                    break;
                case "HRB500":
                    strDiameter = "D";
                    break;
                case "HRB500E":
                    strDiameter = "D";
                    break;
                case "HRB600E":
                    strDiameter = "E";
                    break;
                case "HRB650E":
                    strDiameter = "F";
                    break;
                case "HRB700":
                    strDiameter = "G";
                    break;
                default:
                    strDiameter = "D";
                    break;
            }
            switch (para.main_reinforcement_grade)
            {
                case "HRB300":
                    strMainDiameter = "A";
                    break;
                case "HRB335":
                    strMainDiameter = "B";
                    break;
                case "HRB400":
                    strMainDiameter = "C";
                    break;
                case "HRB500":
                    strMainDiameter = "D";
                    break;
                case "HRB500E":
                    strMainDiameter = "D";
                    break;
                case "HRB600E":
                    strMainDiameter = "E";
                    break;
                case "HRB650E":
                    strMainDiameter = "F";
                    break;
                case "HRB700":
                    strMainDiameter = "G";
                    break;
                default:
                    strMainDiameter = "D";
                    break;
            }
        }

        public void PlotPile(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitle(db, insertPoint, ref ext, "立面", "", scale);

            tH = Math.Abs(double.Parse(pileParameter.top_size.Split('*')[0]));
            tL = Math.Abs(double.Parse(pileParameter.top_size.Split('*')[1]));
            bH = Math.Abs(double.Parse(pileParameter.bottom_size.Split('*')[0]));
            bL = Math.Abs(double.Parse(pileParameter.bottom_size.Split('*')[1]));
            th1 = tH;
            if (tH == 0)
                tH = pileParameter.pile_penetration_depth - pileParameter.Depth;
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -22 * scale - tH);
            Point2d ptDim = M1.C2D(-0.5 * D - 10 * scale);
            //double SheetLength = 297;
            int tN = 15, mN = 20, bN = 10;
            double htHeight = 850;
            if (scale > 5)
            {
                tN = 25;
                mN = 30;
                bN = 20;
            }
            double SheetLength1 = pileParameter.top_encryption_spacing * tN;
            double SheetLength2 = pileParameter.top_encryption_spacing * 5 + pileParameter.middle_encryption_spacing * (mN - 10) + pileParameter.bottom_encryption_spacing * 5;
            double SheetLength3 = pileParameter.bottom_encryption_spacing * bN + bH;
            spiralDia = GeneralRebar.outerDiaNew[pileParameter.spiral_reinforcement_diameter] * 0.1;
            List<double> listTop = new List<double>();
            List<double> listTopUpper = new List<double>();
            List<double> listBottom = new List<double>();
            List<Point3d> listPt = SteelBar.calculatePileSteelElevationCoordinate(M1.C3D(), pileParameter.main_reinforcement_number, 0.5 * (D - spiralDia), pileParameter.pier_protect_layer, ref listTop);
            List<Point3d> listPtUpper = SteelBar.calculatePileSteelElevationCoordinate(M1.C3D(0, pileParameter.pile_penetration_depth), pileParameter.main_reinforcement_number, 0.5 * (D + tL * 2 - spiralDia), pileParameter.pier_protect_layer, ref listTopUpper);
            Point3d ptN3 = listPtUpper[listPtUpper.Count - 1].C3D(-0.5 * (D - spiralDia) + 5);
            #region  图形绘制
            htTh = pileParameter.steel_casing_thickness * 10;
            #region 上半部分边框绘制

            if (isExistCap)
            {
                //承台
                PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D - 15 * scale), ref ext, "H细线");
                RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(-0.5 * D - 15 * scale, 18 * scale + tH), M1.C2D(-0.5 * D - 15 * scale), scale);
                RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(-0.5 * D - 15 * scale, 18 * scale + tH), M1.C2D(0.5 * D + 15 * scale, 18 * scale + tH), scale);
                RebarPLPloter.CreateBreakLine(db, ref ext, M1.C2D(0.5 * D + 15 * scale, 18 * scale + tH), M1.C2D(0.5 * D + 15 * scale), scale);
                PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D + 15 * scale), ref ext, "H细线");
            }
            else
            {
                listPtUpper = SteelBar.calculatePileSteelElevationCoordinate(M1.C3D(0, pileParameter.pile_penetration_depth - 2), pileParameter.main_reinforcement_number, 0.5 * (D + tL * 2 - spiralDia), pileParameter.pier_protect_layer, ref listTopUpper);
                PLPloter.AddLine(db, M1.C2D(-0.5 * D, pileParameter.pile_penetration_depth), M1.C2D(0.5 * D, pileParameter.pile_penetration_depth), ref ext, "H细线");
                PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D, pileParameter.pile_penetration_depth), ref ext, "H细线");
                PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D, pileParameter.pile_penetration_depth), ref ext, "H细线");
            }


            PLPloter.AddLine(db, M1.C2D(-0.5 * D), M1.C2D(-0.5 * D, -SheetLength1), ref ext, "H细线");
            PLPloter.AddLine(db, M1.C2D(0.5 * D), M1.C2D(0.5 * D, -SheetLength1), ref ext, "H细线");

            if (!isExistCap && isAddHT)
            {
                string path = Extensions.curAppPath + "Aviation.dwg";
                string _blcName = "DJLS";
                BlockPlot.InsertBlockByDwg(db, path, _blcName, "H细线", M1.C3D(-0.35 * D, tH + 32), ref ext, 1, 0, true, false);
                PLPloter.AddPloy4(db, M1.C2D(-0.5 * D - htTh * 0.1 * 0.5, pileParameter.pile_penetration_depth - 2), htTh * 0.1 * 0.5, htTh * 0.1 * 0.5, SheetLength1 + pileParameter.pile_penetration_depth - 2, ref ext, "H细线");
                PLPloter.AddPloy4(db, M1.C2D(0.5 * D + htTh * 0.1 * 0.5, pileParameter.pile_penetration_depth - 2), htTh * 0.1 * 0.5, htTh * 0.1 * 0.5, SheetLength1 + pileParameter.pile_penetration_depth - 2, ref ext, "H细线");
                // if(pileParameter.pile_length==1000)
                //     htHeight = 500;
                //else if (pileParameter.pile_length == 2000)
                //     htHeight = 1200;
                //else if (pileParameter.pile_length == 4000)
                //     htHeight = 1200;
                htHeight = pileParameter.steel_casing_length * 1000;


                string valueHT = "Φ" + ((D * 10 + htTh * 2) * 0.1).ToString() + "×" + htTh * 0.1 + "-" + htHeight;
                RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, M1.C3D(0.5 * D + 1, pileParameter.pile_penetration_depth - 2 - 10), "钢护筒", valueHT, Extensions.curFont, scale, 9 * scale, 3 * scale);

                DimPloter.AddLeft2RightBJ(db, "C", M1.C3D(-0.5 * D - 16 * scale, pileParameter.pile_penetration_depth), ref ext, scale, 3, true);
                DimPloter.AddLeft2RightBJ(db, "C", M1.C3D(0.5 * D + 10 * scale, pileParameter.pile_penetration_depth), ref ext, scale, 3, false);
            }
            #endregion

            #region  上半部分绘制

            PLPloter.AddLine(db, M1.C2D(-0.5 * D + pileParameter.pier_protect_layer, pileParameter.Depth), M1.C2D(0.5 * D - pileParameter.pier_protect_layer, pileParameter.Depth), ref ext, "H钢筋");

            if (isExistCap)
            {
                SteelRebar.DrawUpperRebarGrid(db, ref ext, M1, listPt, listPtUpper, 0.5 * (D - pileParameter.pier_protect_layer * 2), pileParameter.top_reinforcement_number, tH, tL, pileParameter.Depth);
                SteelRebar.DrawRebarGrid(db, ref ext, M1, listPt, 0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia), SheetLength1, pileParameter.top_encryption_spacing, 0.5 * D, pileParameter.pile_penetration_depth - tH);
            }
            else
            {
                SteelRebar.DrawUpperRebarGrid(db, ref ext, M1, listPt, listPtUpper, 0.5 * (D - pileParameter.pier_protect_layer * 2), pileParameter.top_reinforcement_number, tH, tL, pileParameter.Depth);
                SteelRebar.DrawRebarGrid(db, ref ext, M1, listPt, 0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia), SheetLength1, pileParameter.top_encryption_spacing, 0.5 * D, pileParameter.pile_penetration_depth - tH);
            }

            DimPloter.AddLeft2RightBJ(db, "A", M1.C3D(-0.5 * D - 6 * scale, -SheetLength1 * 0.3), ref ext, scale, 3, true);
            DimPloter.AddLeft2RightBJ(db, "A", M1.C3D(0.5 * D + 6 * scale, -SheetLength1 * 0.3), ref ext, scale, 3, false);

            DimPloter.DimRadius(db, M1.C3D(0.5 * D, -SheetLength1 * 0.75), M1.C3D(0.5 * D, -SheetLength1 * 0.75), 3 * scale, ref ext, scale, "净" + pileParameter.pier_protect_layer);
            #endregion
            #region 中间部分边框绘制

            Point2d midC = M1.C2D(0, -0.3 * D - SheetLength1);
            listPt = SteelBar.calculatePileSteelElevationCoordinate(midC.C3D(), pileParameter.main_reinforcement_number, 0.5 * (D - spiralDia), pileParameter.pier_protect_layer, ref listTop);
            PLPloter.AddLine(db, midC.C2D(-0.5 * D), midC.C2D(-0.5 * D, -SheetLength2), ref ext, "H细线");
            PLPloter.AddLine(db, midC.C2D(0.5 * D), midC.C2D(0.5 * D, -SheetLength2), ref ext, "H细线");
            if (!isExistCap && isAddHT)
            {
                PLPloter.AddPloy4(db, midC.C2D(-0.5 * D - htTh * 0.1 * 0.5, 0), htTh * 0.1 * 0.5, htTh * 0.1 * 0.5, SheetLength2 * 0.8, ref ext, "H细线");
                PLPloter.AddPloy4(db, midC.C2D(0.5 * D + htTh * 0.1 * 0.5, 0), htTh * 0.1 * 0.5, htTh * 0.1 * 0.5, SheetLength2 * 0.8, ref ext, "H细线");
            }
            SteelRebar.DrawMidRebarGrid(db, ref ext, midC, listPt, 0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia), SheetLength2, pileParameter.top_encryption_spacing, 5, pileParameter.middle_encryption_spacing, mN - 10, pileParameter.bottom_encryption_spacing, 5, 0.5 * D);

            //Point2d ptAdd = midC.C2D(0,-(pileParameter.top_encryption_spacing * 5 + pileParameter.middle_encryption_spacing * 10));
            //double dia =Math.Round( 0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia-(int)pileParameter.outer_strengthen_reinforcement_diameter*0.1 - GlobalFuncs.CalculateReduction(pileParameter.inner_strengthen_reinforcement_diameter,90)*2),1);
            double dia = Math.Round(0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia), 1);
            //PLPloter.AddLine(db,ptAdd.C2D(-dia), ptAdd.C2D(dia), ref ext, "H细线");
            #endregion
            #region 下半部分边框绘制

            Point2d PtBt = midC.C2D(0, -SheetLength2 - 0.3 * D);
            //PLPloter.CreateBreakLine(db, ref ext, PtBt.C2D(-0.5 * D - 2 * scale, 0), PtBt.C2D(0.5 * D +2 * scale, 0), scale);
            PLPloter.AddLine(db, PtBt.C2D(-0.5 * D, 0), PtBt.C2D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ref ext, "H细线");
            PLPloter.AddLine(db, PtBt.C2D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), PtBt.C2D(0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ref ext, "H细线");
            PLPloter.AddLine(db, PtBt.C2D(0.5 * D), PtBt.C2D(0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ref ext, "H细线");
            #endregion

            #region  下半部分绘制
            listPt = SteelBar.calculatePileSteelElevationCoordinate(PtBt.C3D(), pileParameter.main_reinforcement_number, 0.5 * (D - spiralDia), pileParameter.pier_protect_layer, ref listTop);
            List<Point3d> listPtBottom = SteelBar.calculatePileSteelElevationCoordinate(PtBt.C3D(0, -SheetLength3), pileParameter.main_reinforcement_number, 0.5 * (D - bL * 2 - spiralDia), pileParameter.pier_protect_layer, ref listBottom);

            SteelRebar.DrawBottomRebarGrid(db, ref ext, PtBt, listPt, listPtBottom, 0.5 * (D - pileParameter.pier_protect_layer * 2 - spiralDia), SheetLength3, pileParameter.bottom_encryption_spacing, bH, bL, 0.5 * D);

            if (pileParameter.is_out_double_layout)
            {
                DimPloter.AddLeft2RightBJ(db, "B", PtBt.C3D(-0.5 * D - 6 * scale, -SheetLength3 * 0.3), ref ext, scale, 3, true);
                DimPloter.AddLeft2RightBJ(db, "B", PtBt.C3D(0.5 * D + 6 * scale, -SheetLength3 * 0.3), ref ext, scale, 3, false);
            }
            #endregion

            #region 大样

            Point2d ptDYT = M1.C2D(0.5 * D + 30 * scale, pileParameter.pile_penetration_depth - tH);// midC.C2D(0.5 * D + 30 * scale,0);
            Point2d ptDYB = PtBt.C2D(0.5 * D + 30 * scale, -SheetLength3 + bH);
            double topLen = Math.Sqrt(Math.Pow(tH, 2) + Math.Pow(tL, 2));
            double bottomLen = Math.Sqrt(Math.Pow(bH, 2) + Math.Pow(bL, 2));

            SteelRebar.DrawDetails(db, ref ext, scale, ptDYT, ptDYB, tH, tL, bH, bL);

            string noS = pileParameter.main_reinforcement_number + strMainDiameter + ((int)pileParameter.main_reinforcement_diameter).ToString();
            //string valueS =("h+"+( bottomLen+ topLen - 95).ToString("0.0"));
            string valueS = (pileParameter.pile_length + bottomLen + topLen - 95).ToString("0.0");

            //if(pileParameter.main_reinforcement_grade== "HRB650E")
            //    RebarDimPloter.RebarWire650New(db, ref ext, midC.C2D(0.5 * D + 30 * scale, 35 * scale), midC.C3D().C2D(0.5 * D + 30 * scale+2 * scale, 35 * scale - 5 * scale), noS, valueS, "1",strMainDiameter,
            //GeTools.DegreeToRadian(0), Extensions.curFont, scale);
            //else
            RebarDimPloter.RebarWire(db, ref ext, midC.C2D(0.5 * D + 30 * scale, 35 * scale), noS, valueS, 1,
        GeTools.DegreeToRadian(0), Extensions.curFont, scale);

            if (pileParameter.is_out_double_layout)
            {

                Point2d ptDYT1 = M1.C2D(0.5 * D + 30 * scale + 16 * scale, pileParameter.pile_penetration_depth - tH);// midC.C2D(0.5 * D + 30 * scale,0);
                Point2d ptDYB1 = M1.C2D(0.5 * D + 30 * scale + 16 * scale, -pileParameter.out_length * 0.3 + tH);
                double topLen1 = Math.Sqrt(Math.Pow(tH, 2) + Math.Pow(tL, 2));
                double bottomLen1 = Math.Sqrt(Math.Pow(bH, 2) + Math.Pow(bL, 2));

                SteelRebar.DrawDetails(db, ref ext, scale, ptDYT1, ptDYB1, tH, tL, 0, 0, false);

                valueS = (pileParameter.out_length).ToString("0.0");

                //if (pileParameter.main_reinforcement_grade == "HRB650E")
                //    RebarDimPloter.RebarWire650New(db, ref ext, midC.C2D(0.5 * D + 30 * scale + 16* scale, 15 * scale), midC.C3D().C2D(0.5 * D + 30 * scale + 16* scale + 2 * scale, 15 * scale - 5 * scale), noS, valueS, "1a", strMainDiameter,
                //GeTools.DegreeToRadian(0), Extensions.curFont, scale);
                //else
                RebarDimPloter.RebarWireNew(db, ref ext, midC.C2D(0.5 * D + 30 * scale + 16 * scale, 15 * scale), noS, valueS, "1a",
            GeTools.DegreeToRadian(0), Extensions.curFont, scale);
            }
            #endregion
            #endregion
            #region  编号
            int num = pileParameter.top_reinforcement_number - 1;
            double space = tH / num;
            List<double> lList = new List<double>();
            for (int i = 0; i < num - 1; i++)
            {
                lList.Add(space);
            }
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, ptN3.C3D(0, -space), ArrowDirection.South, lList, new List<double>(), "3", scale, true, 5, 5 * scale);
            double diaT1 = Math.Round((D - pileParameter.pier_protect_layer * 2 - spiralDia) + ((int)pileParameter.top_reinforcement_diameter * 0.1 - spiralDia) * 2, 1);
            double diaT2 = Math.Round((D - pileParameter.pier_protect_layer * 2 - spiralDia) + ((int)pileParameter.top_reinforcement_diameter * 0.1 - spiralDia) * 2, 1);
            if(tL>0)
                diaT2 = Math.Round((D - pileParameter.pier_protect_layer * 2 - spiralDia) + ((int)pileParameter.top_reinforcement_diameter * 0.1 - spiralDia) * 2, 1) + tL * 2 - 1;
            double len3 = Math.Round(Math.PI * (diaT1 + diaT2) * 0.5 + (int)pileParameter.top_reinforcement_diameter, 1);
            N3Len = len3;
            N3Dia1 = diaT1;
            N3Dia2 = diaT2;
            //Tuple<int, eDB, int, double> tu = new Tuple<int, eDB, int, double>(3, pileParameter.top_reinforcement_diameter, pileParameter.top_reinforcement_number, len3);
            //rebarLst.Add(tu);

            //4/5
            double re = GlobalFuncs.CalculateReduction(pileParameter.inner_strengthen_reinforcement_diameter, 90);
            //double dRC = GeneralRebar.outerDiaOld[pileParameter.outer_strengthen_reinforcement_diameter];
            //double dRMain = GeneralRebar.outerDiaOld[pileParameter.main_reinforcement_diameter];
            double dRC = GeneralRebar.outerDiaNew[pileParameter.outer_strengthen_reinforcement_diameter];
            double dRMain = GeneralRebar.outerDiaNew[pileParameter.main_reinforcement_diameter];
            //double dia4 = Math.Round((D - pileParameter.pier_protect_layer * 2 - spiralDia*2 - dRMain * 0.1*2- dRC*0.1), 1, MidpointRounding.AwayFromZero);
            double dia4 = Math.Round((D - pileParameter.pier_protect_layer * 2 - spiralDia * 2 - dRMain * 0.1 * 2 - dRC * 0.1), 1, MidpointRounding.AwayFromZero);
            double len4 = Math.Round(Math.PI * dia4 + (int)pileParameter.outer_strengthen_reinforcement_diameter, 1);
            N4Dia = dia4;
            N4Len = len4;
            N4 = (int)(pileParameter.pile_length / pileParameter.outer_strengthen_reinforcement_spacing) + 1;
            //tu = new Tuple<int, eDB, int, double>(4, pileParameter.outer_strengthen_reinforcement_diameter, N4, len4);
            //rebarLst.Add(tu);
            if (pileParameter.inner_strengthen_reinforcement_diameter != eDB.None)
            {
                //RebarPLPloter.CreateLineArrowMultDBNew(db, ref ext, ptAdd.C3D(dia - 2 * scale), ArrowDirection.North, new List<double>(), new List<double>(), "4", "5", scale, true, 2, D * 0.5);

                double len5 = Math.Round(Math.Sqrt(3) * dia4 * 0.5, 1) + 2 * GeneralRebar.outerDiaHoke[pileParameter.inner_strengthen_reinforcement_diameter];
                N5Len = len5;
                //tu = new Tuple<int, eDB, int, double>(5, pileParameter.inner_strengthen_reinforcement_diameter, N4*3, len5);
                //rebarLst.Add(tu);
            }
            //else
            //    RebarPLPloter.CreateLineArrowDBNew(db, ref ext, ptAdd.C3D(dia - 2 * scale), ArrowDirection.North, new List<double>(), new List<double>(), "4", scale, true, 2, D * 0.5);

            lList = new List<double>();
            for (int i = 0; i < listPt.Count - 1; i++)
            {

                lList.Add(Math.Abs(listPt[i + 1].X - listPt[i].X));
            }
            double wR = 0.5 * D - pileParameter.pier_protect_layer - listTop[0];
            ////1
            RebarPLPloter.CreateLineArrowDBNew(db, ref ext, midC.C3D(-0.5 * D + pileParameter.pier_protect_layer + wR, -pileParameter.top_encryption_spacing * 5 - 5), ArrowDirection.West, new List<double>(), lList, "1", scale, true, 4);
            double len1 = pileParameter.pile_length + (bottomLen + topLen - 95);
            //tu = new Tuple<int, eDB, int, double>(1, pileParameter.main_reinforcement_diameter, pileParameter.main_reinforcement_number, len1);
            //rebarLst.Add(tu);



            #endregion
            #region  标注
            //顶部标注

            if (isExistCap)
            {
                DimPloter.DimRot(db, M1.C3D(-0.5 * D), M1.C3D(-0.5 * D, pileParameter.pile_penetration_depth - tH), ptDim.C3D(5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimRotated(db, ref ext, M1.C3D(-0.5 * D, pileParameter.pile_penetration_depth - tH), M1.C3D(-0.5 * D, space * num + pileParameter.Depth), ptDim.C3D(5 * scale), 90, scale, Unit.Centimeter, Unit.Centimeter, "", "", (int)space);
            }
            else
            {
                DimPloter.DimRot(db, M1.C3D(-0.5 * D, tH), M1.C3D(-0.5 * D, pileParameter.pile_penetration_depth), ptDim.C3D(5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimRotated(db, ref ext, M1.C3D(-0.5 * D, 0), M1.C3D(-0.5 * D, space * num), ptDim.C3D(5 * scale), 90, scale, Unit.Centimeter, Unit.Centimeter, "", "", (int)space);
            }
            if (isAddHT)
            {
                DimPloter.DimRot(db, M1.C3D(0.5 * D, pileParameter.pile_penetration_depth - 2), M1.C3D(0.5 * D, pileParameter.pile_penetration_depth), M1.C3D(0.5 * D + 15 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimRot(db, M1.C3D(0.5 * D, pileParameter.pile_penetration_depth - 2), midC.C3D(0.5 * D, -SheetLength2 * 0.8), M1.C3D(0.5 * D + 15 * scale), ref ext, 90, scale, (htHeight * 0.1).ToString(), Unit.Centimeter, Unit.Centimeter);
            }
            if (pileParameter.pile_penetration_depth - pileParameter.Depth - space * num > 0)
                DimPloter.DimRot(db, M1.C3D(-0.5 * D, pileParameter.Depth + space * num), M1.C3D(-0.5 * D, pileParameter.pile_penetration_depth), ptDim.C3D(5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRot(db, M1.C3D(-0.5 * D), M1.C3D(-0.5 * D, pileParameter.pile_penetration_depth), ptDim.C3D(), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
            //左侧
            if (th1 == 0)
                DimPloter.DimRot(db, M1.C3D(-0.5 * D), PtBt.C3D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ptDim.C3D(), ref ext, 90, scale, (pileParameter.pile_length - tH - pileParameter.Depth).ToString(), Unit.Centimeter, Unit.Centimeter);
            else
                DimPloter.DimRot(db, M1.C3D(-0.5 * D), PtBt.C3D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ptDim.C3D(), ref ext, 90, scale, (pileParameter.pile_length ).ToString(), Unit.Centimeter, Unit.Centimeter);
            //DimPloter.DimRot(db, M1.C3D(-0.5 * D), PtBt.C3D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ptDim.C3D(), ref ext, 90, scale, "h", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRot(db, PtBt.C3D(-0.5 * D, -SheetLength3), PtBt.C3D(-0.5 * D, -SheetLength3 - pileParameter.bottom_distance), ptDim.C3D(5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRot(db, PtBt.C3D(-0.5 * D, -SheetLength3), PtBt.C3D(-0.5 * D, -SheetLength3 + bH), ptDim.C3D(5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);


            DimPloter.DimRot(db, PtBt.C3D(-0.5 * D, -SheetLength3), PtBt.C3D(0.5 * D, -SheetLength3), PtBt.C3D(0, -SheetLength3 - 10 * scale), ref ext, 0, scale, "D=<>", Unit.Centimeter, Unit.Centimeter);
            #endregion

        }

        public  void PlotPileSpiral(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);

            #region  绘制
            Point2d ptS = insertPoint.C2D();
            double w2 = pileParameter.pile_diameter-2*pileParameter.pier_protect_layer- spiralDia;       
            Point3d ptD = insertPoint.C3D(w2*0.5);
            Point3d ptDim = insertPoint.C3D(w2 * 0.5+4*scale);
            Point3d ptDimL = insertPoint.C3D(-w2 * 0.5 - 4 * scale);
            Point2d bottomPier = new Point2d();
            if (pileParameter.pile_length - bH - pileParameter.top_encryption_length < 0)
                pileParameter.top_encryption_length = pileParameter.pile_length - bH - 100;
                SteelBarS.CreatePierPartSteelBar(db, ref ext, out bottomPier, ptS, w2-bL*2, w2, bH, pileParameter.bottom_encryption_spacing, false, eLocation.Bottom);

            DimPloter.DimRot(db, insertPoint.C3D(-(w2 - bL * 2) * 0.5), insertPoint.C3D((w2 - bL * 2) * 0.5), ptDim.C3D(0,-4*scale), ref ext, 0, scale, "D=<>", Unit.Centimeter, Unit.Centimeter,1);
            DimPloter.DimRot(db, insertPoint.C3D(0.5 * w2), bottomPier.C3D(), ptDim.C3D(), ref ext, 90, scale, bH/ pileParameter.bottom_encryption_spacing+"×"+ pileParameter.bottom_encryption_spacing, Unit.Centimeter, Unit.Centimeter);
        

            Point2d bottomEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out bottomEnd, bottomPier.C2D(), w2, pileParameter.bottom_encryption_spacing * 10, pileParameter.bottom_encryption_spacing , false, eLocation.Bottom,false);
          
            Point2d middleEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out middleEnd, bottomEnd, w2, pileParameter.middle_encryption_spacing  * 8, pileParameter.middle_encryption_spacing, false, eLocation.Middle);
            string txt = (pileParameter.pile_length - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length)).ToString("0.0");

           

            //DimPloter.DimRot(db, middleEnd.C3D(), bottomEnd.C3D(), ptDim.C3D(), ref ext, 90, scale, "h-"+(pileParameter.top_encryption_length+ pileParameter.bottom_encryption_length), Unit.Centimeter, Unit.Centimeter);
            if (pileParameter.bottom_encryption_length != 0)
            {
                if (th1 == 0)
                    txt = (pileParameter.pile_length - tH-pileParameter.Depth - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length)).ToString("0.0");
                DimPloter.DimRot(db, bottomPier.C3D(), bottomEnd.C3D(), ptDim.C3D(), ref ext, 90, scale, (pileParameter.bottom_encryption_length - bH) / pileParameter.bottom_encryption_spacing + "×" + pileParameter.bottom_encryption_spacing, Unit.Centimeter, Unit.Centimeter);
                DimPloter.DimRot(db, middleEnd.C3D(), bottomEnd.C3D(), ptDim.C3D(), ref ext, 90, scale, txt, Unit.Centimeter, Unit.Centimeter);
            }
            else
            {
                //txt = (pileParameter.pile_length - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length)-bH).ToString("0.0");
                if (th1 == 0)
                    txt = (pileParameter.pile_length-tH - pileParameter.Depth - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length) - bH).ToString("0.0");
                else
                    txt = (pileParameter.pile_length - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length) - bH).ToString("0.0");
                DimPloter.DimRot(db, middleEnd.C3D(), bottomPier.C3D(), ptDim.C3D(), ref ext, 90, scale, txt, Unit.Centimeter, Unit.Centimeter);
            }
            //DimPloter.DimRot(db, middleEnd.C3D(), bottomEnd.C3D(), ptDim.C3D(), ref ext, 90, scale, (pileParameter.middle_encryption_length) / pileParameter.middle_encryption_spacing + "×" + pileParameter.middle_encryption_spacing, Unit.Centimeter, Unit.Centimeter);
            DimPloter.DimRot(db, middleEnd.C3D(0, -pileParameter.middle_encryption_spacing*1.5), middleEnd.C3D(0,-pileParameter.middle_encryption_spacing*2.5), ptDimL.C3D(), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);

            Point2d topEnd = new Point2d();
            SteelBarS.CreatePartSteelBar(db, ref ext, out topEnd, middleEnd, w2, pileParameter.top_encryption_spacing  * 15, pileParameter.top_encryption_spacing, false, eLocation.Top);
            DimPloter.DimRot(db, middleEnd.C3D(), topEnd.C3D(), ptDim.C3D(), ref ext, 90, scale, (pileParameter.top_encryption_length) / pileParameter.top_encryption_spacing + "×" + pileParameter.top_encryption_spacing, Unit.Centimeter, Unit.Centimeter);

            DimPloter.DimRot(db, topEnd.C3D(-w2 ), topEnd.C3D(), topEnd.C3D(0, 10 * scale), ref ext, 0, scale, "D=<>", Unit.Centimeter, Unit.Centimeter,1);
            #endregion
            #region  编号
            if (pileParameter.bottom_encryption_length > 0)
            {
                if (th1 == 0)
                    pileParameter.middle_encryption_length= pileParameter.pile_length - tH - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length);
                else
                    pileParameter.middle_encryption_length = pileParameter.pile_length - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length);
            }
            else
            {
                if (th1 == 0)
                    pileParameter.middle_encryption_length = pileParameter.pile_length - tH - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length) - bH;
                else
                    pileParameter.middle_encryption_length = pileParameter.pile_length - (pileParameter.top_encryption_length + pileParameter.bottom_encryption_length) - bH;
            }
            double tSL = GlobalFuncs.GetSpiralLength(pileParameter.top_encryption_length, spiralDia, pileParameter.top_encryption_spacing, pileParameter.pile_diameter - spiralDia, pileParameter.pier_protect_layer);
            double mSL = GlobalFuncs.GetSpiralLength(pileParameter.middle_encryption_length, spiralDia, pileParameter.middle_encryption_spacing, pileParameter.pile_diameter - spiralDia, pileParameter.pier_protect_layer);
            double bSL = 0;
            if (pileParameter.bottom_encryption_length > 0)
                bSL = GlobalFuncs.GetSpiralLength(pileParameter.bottom_encryption_length - bH, spiralDia, pileParameter.bottom_encryption_spacing, pileParameter.pile_diameter - spiralDia, pileParameter.pier_protect_layer);
            
            double pBSL = GlobalFuncs.GetSpiralTopLength(spiralDia, 1, pileParameter.pile_diameter , pileParameter.pier_protect_layer);
            double pTSL = GlobalFuncs.GetSpiralTopLength(spiralDia, 1, pileParameter.pile_diameter - bL * 2, pileParameter.pier_protect_layer);
            double rST = GlobalFuncs.GetSpiraldia(spiralDia, pileParameter.pile_diameter, pileParameter.pier_protect_layer);
            double rSB = GlobalFuncs.GetSpiraldia(spiralDia, pileParameter.pile_diameter - bL * 2, pileParameter.pier_protect_layer);
            double pSL = GlobalFuncs.GetSpiralLength(bH, (rST + rSB) * 0.5, pileParameter.bottom_encryption_spacing);
            double L = (tSL + mSL + bSL + pBSL + pTSL + pSL)+2*Math.PI* rST+20* spiralDia;
            //Tuple<int, eDB, int, double> tu = new Tuple<int, eDB, int, double>(2, pileParameter.spiral_reinforcement_diameter, 1, L);
            //rebarLst.Add(tu);
            string valueS = (L).ToString("0.0");
            //string noS = "1Ф" + ((int)pileParameter.spiral_reinforcement_diameter).ToString();
            string noS = strDiameter + ((int)pileParameter.spiral_reinforcement_diameter).ToString();
            RebarDimPloter.RebarWire(db, ref ext, topEnd.C2D(-w2 * 0.5, 0), noS, valueS, 2,
               GeTools.DegreeToRadian(0), Extensions.curFont, scale);
            #endregion

            #region 三角撑大样
            Point2d pt5 = topEnd.C2D(-w2,35 * scale);
            SteelBarPileCap.AddLineSample(pt5.C2D(), pt5.C2D(Math.Round(D, 1)), ref ext, "H钢筋", eSampleType.UT, 2.5 * scale);

            valueS = (N5Len).ToString("0.0");
            noS = strMainDiameter + ((int)pileParameter.inner_strengthen_reinforcement_diameter).ToString();
            RebarDimPloter.RebarWire(db, ref ext, pt5.C2D(D * 0.5), noS, valueS, 5,
               GeTools.DegreeToRadian(0), Extensions.curFont, scale,18);

            //DimPloter.DimRot(db, pt5.C3D(), pt5.C3D(0, 2.5 * scale), pt5.C3D(-5 * scale), ref ext, 90, scale, "", Unit.Centimeter, Unit.Centimeter);
            //DimPloter.DimRot(db, pt5.C3D(D), pt5.C3D(D, 2.5 * scale), pt5.C3D(D + 5 * scale), ref ext, 90, scale, "15", Unit.Centimeter, Unit.Centimeter);
            TextPloter.AddDBText(db,pt5.C3D(D * 0.2, 0.5 * scale), ref ext, Math.Round(Math.Sqrt(3) * N4Dia * 0.5, 1).ToString("0.0"), scale);
            #endregion
        }

        public void PlotCPile(ref Database db, out Extents2d ext, Point2d insertPoint, int scale)
        {
            ext = new Extents2d(insertPoint, insertPoint);

            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -8 * scale - D * 0.5);

            ext = new Extents2d(insertPoint, insertPoint);
            TextPloter.AddTitle(db,insertPoint, ref ext, "A-A", "", scale);
            //double dRSpiral =(int)pileParameter.spiral_reinforcement_diameter;
            double dRSpiral = GeneralRebar.outerDiaNew[pileParameter.spiral_reinforcement_diameter];
            double dRC = GeneralRebar.outerDiaNew[pileParameter.outer_strengthen_reinforcement_diameter];
            double dRMain = GeneralRebar.outerDiaNew[pileParameter.main_reinforcement_diameter];
            //double dRSpiral =(double)pileParameter.spiral_reinforcement_diameter*0.1;
            //double dRC = (double)pileParameter.outer_strengthen_reinforcement_diameter * 0.1;
            //double dRMain = (double)pileParameter.main_reinforcement_diameter * 0.1;
            double cover = pileParameter.pier_protect_layer;
            double re = GlobalFuncs.CalculateReduction(pileParameter.inner_strengthen_reinforcement_diameter, 90);
            double dia4 =N4Dia*0.5;
        

            if (pileParameter.is_out_double_layout)
            {
                TextPloter.AddTitle(db,insertPoint.C2D(D * 1.75), ref ext, "B-B", "", scale);
                //平面图
                CreateFacadeReinforcementCageOutDouble(db, ref ext, M1.C3D(), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);

                //平面图
                CreateFacadeReinforcementCage(db, ref ext, M1.C3D(D * 1.75), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);

                string noS = " " + ((int)(pileParameter.pile_length / 200) + 1) + strMainDiameter + ((int)pileParameter.outer_strengthen_reinforcement_diameter);
                string valueS = (N4Len).ToString();
                string rS = ((int)pileParameter.outer_strengthen_reinforcement_diameter).ToString();
                // 三角撑
                CreatePileTriangleTie(db, ref ext, M1.C3D(D * 2.75), dia4, noS, valueS, 4, scale, pileParameter.inner_strengthen_reinforcement_num, true, true, rS, "D" + N4Dia);
                //drs = dtRebar.Select("no=4");

                noS = pileParameter.top_reinforcement_number + strDiameter + (int)pileParameter.top_reinforcement_diameter;
                if (N3Dia1 == N3Dia2)
                    valueS = (N3Len).ToString();
                else
                    valueS = "均" + (N3Len).ToString();
                rS = ((int)pileParameter.top_reinforcement_diameter).ToString();
                //// 顶面
                if (N3Dia1 == N3Dia2)
                    CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4.25), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 );
                else
                    CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4.25), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 + "～" + "D" + N3Dia2);
                DimPloter.DimRadius(db,M1.C3D(0.5 * D, 0), M1.C3D(0.5 * D, 0), 3 * scale, ref ext, scale, "净" + pileParameter.pier_protect_layer);
            }
            else
            {
                if (pileParameter.inner_strengthen_reinforcement_num != 6)
                {
                    if (!isExistCap && isAddHT)
                    {
                        //平面图
                        CreateFacadeReinforcementCage(db, ref ext, M1.C3D(), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);
                        TextPloter.AddTitle(db, insertPoint.C2D(D * 1.75), ref ext, "C-C", "", scale);
                        CreateFacadeReinforcementCageHT(db, ref ext, M1.C3D(D * 1.75), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);
                        string path = Extensions.curAppPath + "Aviation.dwg";
                        string _blcName = "HTong";
                        BlockPlot.InsertBlockByDwg(db, path, _blcName, "H细线", M1.C3D(D * 1.75, 0), ref ext, 1, 0, true, false);
                        //System.Data.DataRow[] drs = dtRebar.Select("no=3");
                        //string noS = "α+1" + strDiameter + ((int) pileParameter.outer_strengthen_reinforcement_diameter);
                        string noS = " " + ((int)(pileParameter.pile_length / 200) + 1) + strMainDiameter + ((int)pileParameter.outer_strengthen_reinforcement_diameter);
                        string valueS = (N4Len).ToString();
                        string rS = ((int)pileParameter.outer_strengthen_reinforcement_diameter).ToString();
                        // 三角撑
                     
                        CreatePileTriangleTie(db, ref ext, M1.C3D(D * 2.75), dia4, noS, valueS, 4, scale, pileParameter.inner_strengthen_reinforcement_num, true, true, rS, "D" + N4Dia);
                      
                        // 中间圆
                        double valueX = dia4 * Math.Cos(GeTools.DegreeToRadian(45));
                        Point3d pt1 = M1.C3D(D * 2.75).C3D(dia4).C3D(-valueX, valueX);
                        RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "4", (dia4) * 0.2, scale, 135);
                        //drs = dtRebar.Select("no=4");

                        noS = pileParameter.top_reinforcement_number + strDiameter + (int)pileParameter.top_reinforcement_diameter;
                        if(N3Dia1== N3Dia2)
                            valueS = (N3Len).ToString();
                        else
                            valueS = "均" + (N3Len).ToString();
                        rS = ((int)pileParameter.top_reinforcement_diameter).ToString();
                        //// 顶面
                        if (N3Dia1 == N3Dia2)
                            CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4.25), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1);
                       else
                            CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4.25), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 + "～" + "D" + N3Dia2);
                        double R3 = D * 0.5 - cover - dRSpiral;
                        // 中间圆
                        valueX = R3 * Math.Cos(GeTools.DegreeToRadian(45));
                        pt1 = M1.C3D(D * 4.25).C3D(R3).C3D(-valueX, valueX);
                        RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "3", (R3)*0.2, scale, 135);
                        // 圆形标记
                        double R1 = D * 0.5 - cover - dRSpiral;
                        //DimPloter.CircularMark(db, ref ext, M1.C3D(D * 4.25).C3D(-R1*Math.Cos(45), R1 * Math.Sin(45)), "1", Extensions.curFont, scale);
                        DimPloter.DimRadius(db, M1.C3D(0.5 * D, 0), M1.C3D(0.5 * D, 0), 3 * scale, ref ext, scale, "净" + pileParameter.pier_protect_layer);
                    }
                    else
                    {
                        //平面图
                        CreateFacadeReinforcementCage(db, ref ext, M1.C3D(), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);

                        //System.Data.DataRow[] drs = dtRebar.Select("no=3");
                        //string noS = "α+1" + strDiameter + ((int) pileParameter.outer_strengthen_reinforcement_diameter);
                        string noS = " " + ((int)(pileParameter.pile_length / 200) + 1) + strMainDiameter + ((int)pileParameter.outer_strengthen_reinforcement_diameter);
                        string valueS = (N4Len).ToString();
                        string rS = ((int)pileParameter.outer_strengthen_reinforcement_diameter).ToString();
                        // 三角撑
                        CreatePileTriangleTie(db, ref ext, M1.C3D(D * 2), dia4, noS, valueS, 4, scale, pileParameter.inner_strengthen_reinforcement_num, true, true, rS, "D" + N4Dia);
                        //drs = dtRebar.Select("no=4");

                        noS = pileParameter.top_reinforcement_number + strDiameter + (int)pileParameter.top_reinforcement_diameter;
                        //valueS = "均" + (N3Len).ToString();
                        if (N3Dia1 == N3Dia2)
                            valueS = (N3Len).ToString();
                        else
                            valueS = "均" + (N3Len).ToString();
                        rS = ((int)pileParameter.top_reinforcement_diameter).ToString();
                        //// 顶面
                        if (N3Dia1 == N3Dia2)
                            CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 );
                        else
                            CreatePileTriangleTie(db, ref ext, M1.C3D(D * 4), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 + "～" + "D" + N3Dia2);
                        DimPloter.DimRadius(db, M1.C3D(0.5 * D, 0), M1.C3D(0.5 * D, 0), 3 * scale, ref ext, scale, "净" + pileParameter.pier_protect_layer);
                    }
                }
                else
                {
                    //平面图
                    CreateFacadeReinforcementCage(db, ref ext, M1.C3D(), D * 0.5, D * 0.5 - pileParameter.pier_protect_layer - Math.Round(dRSpiral * 0.1 * 0.5, 1), dia4, pileParameter.main_reinforcement_number, "1", "2", "4", scale, dRMain);

                    //System.Data.DataRow[] drs = dtRebar.Select("no=3");
                    //string noS = "α+1" + strDiameter + ((int) pileParameter.outer_strengthen_reinforcement_diameter);
                    string noS = " " + ((int)(pileParameter.pile_length / 200) + 1) + strMainDiameter + ((int)pileParameter.outer_strengthen_reinforcement_diameter);
                    string valueS = (N4Len).ToString();
                    string rS = ((int)pileParameter.outer_strengthen_reinforcement_diameter).ToString();
                    // 三角撑
                    CreatePileTriangleTie(db, ref ext, M1.C3D(D * 1.1), dia4, noS, valueS, 4, scale, pileParameter.inner_strengthen_reinforcement_num, true, true, rS, "D" + N4Dia);
                    //drs = dtRebar.Select("no=4");

                    noS = pileParameter.top_reinforcement_number + strDiameter + (int)pileParameter.top_reinforcement_diameter;
                    if (N3Dia1 == N3Dia2)
                        valueS = (N3Len).ToString();
                    else
                        valueS = "均" + (N3Len).ToString();
                    rS = ((int)pileParameter.top_reinforcement_diameter).ToString();
                    //// 顶面
                    if (N3Dia1 == N3Dia2)
                        CreatePileTriangleTie(db, ref ext, M1.C3D(D * 2.5), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 );
                    else
                        CreatePileTriangleTie(db, ref ext, M1.C3D(D * 2.5), D * 0.5 - cover - dRSpiral, noS, valueS, 3, scale, pileParameter.inner_strengthen_reinforcement_num, false, true, rS, "D" + N3Dia1 + "～" + "D" + N3Dia2);


                    DimPloter.DimRadius(db,M1.C3D(0.5 * D, 0), M1.C3D(0.5 * D, 0), 3 * scale, ref ext, scale, "净" + pileParameter.pier_protect_layer);


                    string path = Extensions.curAppPath + "HRB650E.dwg";
                    string _blcName = "TowerPileNew";
                    BlockPlot.InsertBlockByDwg(db, path, _blcName, "H钢筋", M1.C3D(D * 3.8, -30 * scale), ref ext, scale / 0.3, 0, true, false);

                    //Dictionary<string, Dictionary<string, string>> attNameValues = new Dictionary<string, Dictionary<string, string>>();
                    //Dictionary<string, string> value = new Dictionary<string, string>();
                    //value.Add("1", "string");
                    //attNameValues.Add("N1", value);
                    //value = new Dictionary<string, string>();
                    //value.Add("单面焊接", "string");
                    //attNameValues.Add("txt1", value);
                    //value = new Dictionary<string, string>();
                    //value.Add("焊接", "string");
                    //attNameValues.Add("txt2", value);
                    //value = new Dictionary<string, string>();
                    //value.Add(((int)(pileParameter.main_reinforcement_diameter)).ToString(), "string");
                    //attNameValues.Add("DIA", value);
                    //value = new Dictionary<string, string>();
                    //value.Add("4", "string");
                    //attNameValues.Add("N4", value);
                    //value = new Dictionary<string, string>();
                    //value.Add("5", "string");
                    //attNameValues.Add("N5", value);
                    //BlockPlot.InsertBlockByDwgWithPara(db, path, _blcName, "H钢筋", M1.C3D(D * 3.8,-30*scale), ref ext, scale /0.3, 0, attNameValues,true, false);
                }
            }
        }
      
        /// <summary>
        /// 桩基截面
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="pt"></param>
        /// <param name="radius1"></param>
        /// <param name="radius2"></param>
        /// <param name="radius3"></param>
        /// <param name="rebarNum"></param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        /// <param name="Radia"></param>
        public void CreateFacadeReinforcementCage(Database db, ref Extents2d ext,
Point3d pt, double radius1, double radius2, double radius3, int rebarNum,
string T1, string T2, string T3, double scale, double Radia = 30)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region 圆环
                // 外圆
                Circle exCircle = new Circle(pt, Vector3d.ZAxis, radius1) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));

                // 中间圆
                Circle circle = new Circle(pt, Vector3d.ZAxis, radius2) { LayerId = lt["H钢筋"] };
                res.Add(circle);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));

                // 内圆
                Circle innerCircle = new Circle(pt, Vector3d.ZAxis, radius3) { LayerId = lt["H钢筋"] };
                ext = ext.Add(new Extents2d(innerCircle.Bounds.Value.MinPoint.C2D(), innerCircle.Bounds.Value.MaxPoint.C2D()));
                res.Add(innerCircle);

                // 钢筋半径
                double reBarRadius = Radia;

                // 圆点中心坐标
                List<Entity> list = new List<Entity>();
                Circle circlePoint = new Circle(pt.C3D(-(radius2 - (radius2- radius3)*0.5)), Vector3d.ZAxis, 1.6) { ColorIndex = 6 };
                list= ArrayPloter.ArrayPolarEntity(circlePoint,db, rebarNum, 360, pt.C3D(),"H点筋",true);
                #endregion

                #region 标记
                // 圆心坐标
                Point3d circleCenter = pt.C3D();


                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter.C3D(), radius1, scale, 30, string.Format("R{0}", radius1), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale, -30, string.Format("R{0}", radius2), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale, 15, string.Format("R{0}", radius3), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                #endregion

                #region 标注
                if (list != null && list.Count > 0)
                {
                    Point3d p1, p2, p3 = new Point3d(), p4, p5;
                    double offsetX = radius1 / 2;
                    double offsetY = radius1 / 2;
                    int index = 2;
                    if (index < list.Count)
                    {
                        Circle c = list[index] as Circle;
                        p1 = c.Center;
                        p3 = p1.C3D(-offsetX / 2, -offsetY);

                        Polyline Line1 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        Line1.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.C2D(), Line1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line1);
                    }

                    if (index + 1 < list.Count)
                    {
                        Circle c = list[index + 1] as Circle;
                        p2 = c.Center;
                        p4 = new Point3d(p2.X - offsetX / 2, p3.Y, 0);
                        Polyline Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line2.AddVertexAt(0, p2.C2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        p5 = p3.C3D(-offsetX * 0.5);
                        Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        if (p5.X - p3.X > p5.X - p4.X)
                        {
                            Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        }
                        else
                        {
                            Line2.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        }
                        Line2.AddVertexAt(0, p5.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        // 圆形标记
                        DimPloter.CircularMark(db, ref ext, p5.C3D(-2.5 * scale * 2), T1, Extensions.curFont, scale);
                    }

                    //// 圆环标记
                    //// 外圆
                    //double valueX = radius1 * Math.Cos(GeTools.DegreeToRadian(45));
                    //Point3d pt1 = circleCenter.C3D(radius1);
                    //RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "7", (radius1 - radius2) * 10, scale, 0);

                    // 中间圆
                    double valueX = radius2 * Math.Cos(GeTools.DegreeToRadian(45));
                    Point3d pt1 = circleCenter.C3D(valueX, -valueX);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T2, (radius1 - radius2) * 3, scale, -45);

                    //// 内圆
                    valueX = radius3 * Math.Cos(GeTools.DegreeToRadian(265));
                    double valueY = radius3 * Math.Sin(GeTools.DegreeToRadian(265));
                    pt1 = circleCenter.C3D(valueX, valueY);
                    //pt1 = circleCenter.C3D(0, -radius3);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T3, (radius1 - radius2) * 3, scale, 270);
                }
                #endregion

                //#region 声测管
                List<Entity> listAcoustic = new List<Entity>();
                Circle circleAcoustic = new Circle(pt.C3D(-(radius3 -2.4)), Vector3d.ZAxis, 2.4) { ColorIndex = 1 };
                listAcoustic = ArrayPloter.ArrayPolarEntity(circleAcoustic, db, pileParameter.acoustic_tube_number, 360, pt.C3D(), "H粗线", false);
                int num = 270 / (360 / pileParameter.acoustic_tube_number);
                Circle cAcoustic = listAcoustic[num] as Circle;
                RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, cAcoustic.Center, "声测管", "Ф" + pileParameter.acoustic_tube_type.Replace("*", "×"), Extensions.curFont, scale,6*scale);
                //#endregion

                //// 两点之间的间距标注
                Circle c1 = list[list.Count-1] as Circle;
                Circle c2 = list[list.Count-2] as Circle;
                if (c1.Center.X < circleCenter.X)
                {
                    if (c1.Center.Y < circleCenter.Y)
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    else
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                }
                else
                {
                    if (c1.Center.Y < circleCenter.Y)
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    else
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();

            }
        }

        public void CreateFacadeReinforcementCageHT(Database db, ref Extents2d ext,
Point3d pt, double radius1, double radius2, double radius3, int rebarNum,
string T1, string T2, string T3, double scale, double Radia = 30)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region 圆环
                // 外圆
                Circle exCircle = new Circle(pt, Vector3d.ZAxis, radius1) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                // 外圆
                Circle exCircle0 = new Circle(pt, Vector3d.ZAxis, radius1+2) { LayerId = lt["H粗线"] };
                res.Add(exCircle0);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));

                // 中间圆
                Circle circle = new Circle(pt, Vector3d.ZAxis, radius2) { LayerId = lt["H钢筋"] };
                res.Add(circle);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));

                // 内圆
                Circle innerCircle = new Circle(pt, Vector3d.ZAxis, radius3) { LayerId = lt["H钢筋"] };
                ext = ext.Add(new Extents2d(innerCircle.Bounds.Value.MinPoint.C2D(), innerCircle.Bounds.Value.MaxPoint.C2D()));
                res.Add(innerCircle);

                // 钢筋半径
                double reBarRadius = Radia;

                // 圆点中心坐标
                List<Entity> list = new List<Entity>();
                Circle circlePoint = new Circle(pt.C3D(-(radius2 - (radius2 - radius3) * 0.5)), Vector3d.ZAxis, 1.6) { ColorIndex = 6 };
                list = ArrayPloter.ArrayPolarEntity(circlePoint, db, rebarNum, 360, pt.C3D(), "H点筋", true);
                #endregion

                #region 标记
                // 圆心坐标
                Point3d circleCenter = pt.C3D();


                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.West, circleCenter.C3D(radius1 + htTh*0.1+radius1 *0.5), radius1*0.5, scale, 0, string.Format("Ф{0}", (radius1+ htTh * 0.1)*2), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);
                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter.C3D(-(radius1+ radius1 * 0.5)), radius1 * 0.5, scale, 0, string.Format("Ф{0}", radius1*2 ), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                //RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale, -30, string.Format("R{0}", radius2), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                //RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale, 15, string.Format("R{0}", radius3), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                #endregion

                #region 标注
                //if (list != null && list.Count > 0)
                //{
                //    Point3d p1, p2, p3 = new Point3d(), p4, p5;
                //    double offsetX = radius1 / 2;
                //    double offsetY = radius1 / 2;
                //    int index = 2;
                //    if (index < list.Count)
                //    {
                //        Circle c = list[index] as Circle;
                //        p1 = c.Center;
                //        p3 = p1.C3D(-offsetX / 2, -offsetY);

                //        Polyline Line1 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                //        Line1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                //        Line1.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                //        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.C2D(), Line1.Bounds.Value.MaxPoint.C2D()));
                //        res.Add(Line1);
                //    }

                //    if (index + 1 < list.Count)
                //    {
                //        Circle c = list[index + 1] as Circle;
                //        p2 = c.Center;
                //        p4 = new Point3d(p2.X - offsetX / 2, p3.Y, 0);
                //        Polyline Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                //        Line2.AddVertexAt(0, p2.C2D(), 0, 0, 0);
                //        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                //        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                //        res.Add(Line2);

                //        p5 = p3.C3D(-offsetX * 0.5);
                //        Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                //        if (p5.X - p3.X > p5.X - p4.X)
                //        {
                //            Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                //        }
                //        else
                //        {
                //            Line2.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                //        }
                //        Line2.AddVertexAt(0, p5.C2D(), 0, 0, 0);
                //        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                //        res.Add(Line2);

                //        // 圆形标记
                //        DimPloter.CircularMark(db, ref ext, p5.C3D(-2.5 * scale * 2), T1, Extensions.curFont, scale);
                //    }

                //    //// 圆环标记
                //    //// 外圆
                //    //double valueX = radius1 * Math.Cos(GeTools.DegreeToRadian(45));
                //    //Point3d pt1 = circleCenter.C3D(radius1);
                //    //RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "7", (radius1 - radius2) * 10, scale, 0);

                //    // 中间圆
                //    double valueX = radius2 * Math.Cos(GeTools.DegreeToRadian(45));
                //    Point3d pt1 = circleCenter.C3D(valueX, -valueX);
                //    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T2, (radius1 - radius2) * 3, scale, -45);

                //    //// 内圆
                //    valueX = radius3 * Math.Cos(GeTools.DegreeToRadian(265));
                //    double valueY = radius3 * Math.Sin(GeTools.DegreeToRadian(265));
                //    pt1 = circleCenter.C3D(valueX, valueY);
                //    //pt1 = circleCenter.C3D(0, -radius3);
                //    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T3, (radius1 - radius2) * 3, scale, 270);
                //}
                #endregion

                //#region 声测管
                //List<Entity> listAcoustic = new List<Entity>();
                //Circle circleAcoustic = new Circle(pt.C3D(-(radius3 - 2.4)), Vector3d.ZAxis, 2.4) { ColorIndex = 1 };
                //listAcoustic = ArrayPloter.ArrayPolarEntity(circleAcoustic, db, pileParameter.acoustic_tube_number, 360, pt.C3D(), "H粗线", false);
                //int num = 270 / (360 / pileParameter.acoustic_tube_number);
                //Circle cAcoustic = listAcoustic[num] as Circle;
                //RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, cAcoustic.Center, "声测管", "Ф" + pileParameter.acoustic_tube_type.Replace("*", "×"), Extensions.curFont, scale, 6 * scale);
                ////#endregion

                ////// 两点之间的间距标注
                //Circle c1 = list[list.Count - 1] as Circle;
                //Circle c2 = list[list.Count - 2] as Circle;
                //if (c1.Center.X < circleCenter.X)
                //{
                //    if (c1.Center.Y < circleCenter.Y)
                //        DimPloter.DimAli(db, c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                //    else
                //        DimPloter.DimAli(db, c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                //}
                //else
                //{
                //    if (c1.Center.Y < circleCenter.Y)
                //        DimPloter.DimAli(db, c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                //    else
                //        DimPloter.DimAli(db, c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                //}

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();

            }
        }

        public void CreateFacadeReinforcementCageOutDouble(Database db, ref Extents2d ext,
Point3d pt, double radius1, double radius2, double radius3, int rebarNum,
string T1, string T2, string T3, double scale, double Radia = 30)
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                #region 圆环
                // 外圆
                Circle exCircle = new Circle(pt, Vector3d.ZAxis, radius1) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));

                // 中间圆
                Circle circle = new Circle(pt, Vector3d.ZAxis, radius2) { LayerId = lt["H钢筋"] };
                res.Add(circle);
                ext = ext.Add(new Extents2d(circle.Bounds.Value.MinPoint.C2D(), circle.Bounds.Value.MaxPoint.C2D()));

                // 内圆
                Circle innerCircle = new Circle(pt, Vector3d.ZAxis, radius3) { LayerId = lt["H钢筋"] };
                ext = ext.Add(new Extents2d(innerCircle.Bounds.Value.MinPoint.C2D(), innerCircle.Bounds.Value.MaxPoint.C2D()));
                res.Add(innerCircle);

                // 钢筋半径
                double reBarRadius = Radia;

                // 圆点中心坐标
                List<Entity> list = new List<Entity>();
                Circle circlePoint = new Circle(pt.C3D(-(radius2 - (radius2 - radius3) * 0.5)), Vector3d.ZAxis, 1.6) { ColorIndex = 6 };
                list = ArrayPloter.ArrayPolarEntity(circlePoint, db, rebarNum, 360, pt.C3D(), "H点筋", true);
                Circle circleOutPoint = new Circle(pt.C3D(-(radius2 - (radius2 - radius3) * 0.5)).C3D(0,4.8), Vector3d.ZAxis, 1.6) { ColorIndex = 6 };
                List<Entity> list1= ArrayPloter.ArrayPolarEntity(circleOutPoint, db, rebarNum, 360, pt.C3D(), "H点筋", true);
                #endregion

                #region 标记
                // 圆心坐标
                Point3d circleCenter = pt.C3D();


                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter.C3D(), radius1, scale, 30, string.Format("R{0}", radius1), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.East, circleCenter, radius2, scale, -30, string.Format("R{0}", radius2), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                RebarDimPloter.ArrowLineAndText(db, ref ext, ArrowDirection.West, circleCenter, radius3, scale, 15, string.Format("R{0}", radius3), TextPloter.eTxtLocation.E_TOP, Extensions.curFont);

                #endregion

                #region 标注
                if (list != null && list.Count > 0)
                {
                    Point3d p1, p2, p3 = new Point3d(), p4, p5;
                    double offsetX = radius1 / 2;
                    double offsetY = radius1 / 2;
                    int index = 2;
                    if (index < list.Count)
                    {
                        Circle c = list[index] as Circle;
                        p1 = c.Center;
                        p3 = p1.C3D(-offsetX / 2, -offsetY);

                        Polyline Line1 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        Line1.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.C2D(), Line1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line1);
                    }

                    if (index + 1 < list.Count)
                    {
                        Circle c = list[index + 1] as Circle;
                        p2 = c.Center;
                        p4 = new Point3d(p2.X - offsetX / 2, p3.Y, 0);
                        Polyline Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line2.AddVertexAt(0, p2.C2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        p5 = p3.C3D(-offsetX * 0.5);
                        Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        if (p5.X - p3.X > p5.X - p4.X)
                        {
                            Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        }
                        else
                        {
                            Line2.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        }
                        Line2.AddVertexAt(0, p5.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        // 圆形标记
                        DimPloter.CircularMark(db, ref ext, p5.C3D(-2.5 * scale * 2), T1, Extensions.curFont, scale);
                    }

                    index = 1;
                    offsetX = radius1/2+5*scale;
                    if (index < list1.Count)
                    {
                        Circle c = list1[index] as Circle;
                        p1 = c.Center;
                        p3 = p1.C3D(-offsetX / 2, -offsetY);

                        Polyline Line1 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        Line1.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line1.Bounds.Value.MinPoint.C2D(), Line1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line1);
                    }

                  
                    if (index + 1 < list1.Count)
                    {
                        Circle c = list1[index + 1] as Circle;
                        p2 = c.Center;
                        p4 = new Point3d(p2.X - offsetX / 2, p3.Y, 0);
                        Polyline Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        Line2.AddVertexAt(0, p2.C2D(), 0, 0, 0);
                        Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        p5 = p3.C3D(-offsetX * 0.5);
                        Line2 = new Polyline() { Closed = false, LayerId = lt["H细线"] };
                        if (p5.X - p3.X > p5.X - p4.X)
                        {
                            Line2.AddVertexAt(0, p4.C2D(), 0, 0, 0);
                        }
                        else
                        {
                            Line2.AddVertexAt(0, p3.C2D(), 0, 0, 0);
                        }
                        Line2.AddVertexAt(0, p5.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(Line2.Bounds.Value.MinPoint.C2D(), Line2.Bounds.Value.MaxPoint.C2D()));
                        res.Add(Line2);

                        // 圆形标记
                        DimPloter.CircularMark(db, ref ext, p5.C3D(-2.5 * scale * 2), T1+"a", Extensions.curFont, scale);
                    }
                    //// 圆环标记
                    //// 外圆
                    //double valueX = radius1 * Math.Cos(GeTools.DegreeToRadian(45));
                    //Point3d pt1 = circleCenter.C3D(radius1);
                    //RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, "7", (radius1 - radius2) * 10, scale, 0);

                    // 中间圆
                    double valueX = radius2 * Math.Cos(GeTools.DegreeToRadian(45));
                    Point3d pt1 = circleCenter.C3D(valueX, -valueX);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T2, (radius1 - radius2) * 3, scale, -45);

                    //// 内圆
                    valueX = radius3 * Math.Cos(GeTools.DegreeToRadian(265));
                    double valueY = radius3 * Math.Sin(GeTools.DegreeToRadian(265));
                    pt1 = circleCenter.C3D(valueX, valueY);
                    //pt1 = circleCenter.C3D(0, -radius3);
                    RebarDimPloter.CreateHookLineMark(db, ref ext, pt1, T3, (radius1 - radius2) * 3, scale, 270);
                }
                #endregion

                //#region 声测管
                List<Entity> listAcoustic = new List<Entity>();
                Circle circleAcoustic = new Circle(pt.C3D(-(radius3 - 2.4)), Vector3d.ZAxis, 2.4) { ColorIndex = 1 };
                listAcoustic = ArrayPloter.ArrayPolarEntity(circleAcoustic, db, pileParameter.acoustic_tube_number, 360, pt.C3D(), "H粗线", false);
                int num = 270 / (360 / pileParameter.acoustic_tube_number);
                Circle cAcoustic = listAcoustic[num] as Circle;
                RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, cAcoustic.Center, "声测管", "Ф" + pileParameter.acoustic_tube_type.Replace("*", "×"), Extensions.curFont, scale, 6 * scale);
                //#endregion

                //// 两点之间的间距标注
                Circle c1 = list[list.Count - 1] as Circle;
                Circle c2 = list[list.Count - 2] as Circle;
                if (c1.Center.X < circleCenter.X)
                {
                    if (c1.Center.Y < circleCenter.Y)
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    else
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(-5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                }
                else
                {
                    if (c1.Center.Y < circleCenter.Y)
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, -5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                    else
                        DimPloter.DimAli(db,c1.Center.C3D(), c2.Center.C3D(), c2.Center.C3D(5 * scale, 5 * scale), ref ext, scale, "", Unit.Centimeter, Unit.Centimeter);
                }

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();

            }
        }

        /// <summary>
        /// 内轮廓+加强筋三角撑
        /// </summary>
        /// <param name="db"></param>
        /// <param name="ext"></param>
        /// <param name="startPoint"></param>
        /// <param name="radius"></param>
        /// <param name="T1"></param>
        /// <param name="T2"></param>
        /// <param name="T3"></param>
        /// <param name="scale"></param>
        /// <param name="isDrawTriangleTie"></param>
        /// <param name="isDrawFaceWeld"></param>
        /// <param name="replaceDim"></param>
        public static void CreatePileTriangleTie(Database db, ref Extents2d ext, Point3d startPoint,
    double radius, string T1, string T2, int T3, double scale,int  innerNum=3, bool isDrawTriangleTie = true,
    bool isDrawFaceWeld = true, string replaceDim = "", string replaceD = "")
        {
            DBObjectCollection res = new DBObjectCollection();
            using (Transaction tr = db.TransactionManager.StartTransaction())
            {
                TextStyleTable st = tr.GetObject(db.TextStyleTableId, OpenMode.ForRead) as TextStyleTable;
                BlockTable blockTbl = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
                BlockTableRecord recorder = tr.GetObject(blockTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
                LayerTable lt = tr.GetObject(db.LayerTableId, OpenMode.ForRead) as LayerTable;
                // 圆
                Circle exCircle = new Circle(startPoint.Add(new Vector3d(radius, 0, 0)), Vector3d.ZAxis, radius) { LayerId = lt["H粗线"] };
                res.Add(exCircle);
                ext = ext.Add(new Extents2d(exCircle.Bounds.Value.MinPoint.C2D(), exCircle.Bounds.Value.MaxPoint.C2D()));


              
                // 三角撑

                Point3d p1, p2, p3, center;
                center = startPoint.C3D(radius);

                if (innerNum != 6)
                {
                    p1 = startPoint.C3D(radius, radius);
                    p2 = center.C3D(-radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));
                    p3 = center.C3D(radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));

                    if (isDrawTriangleTie)
                    {
                        Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H粗线"] };
                        pl1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(1, p2.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(2, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(pl1);
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");

                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(0, 15), ref ext, "H粗线");

                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(0, 15), ref ext, "H粗线");
                    }
                }
                else
                {
                    p1 = startPoint.C3D(radius, radius);
                    p2 = center.C3D(-radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));
                    p3 = center.C3D(radius * Math.Cos(GeTools.DegreeToRadian(30)), -radius * Math.Sin(GeTools.DegreeToRadian(30)));

                    if (isDrawTriangleTie)
                    {
                        Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H粗线"] };
                        pl1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(1, p2.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(2, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(pl1);
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");

                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(0, 15), ref ext, "H粗线");

                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), -15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(0, 15), ref ext, "H粗线");
                    }

                    p1 = startPoint.C3D(radius, -radius);
                    p2 = center.C3D(-radius * Math.Cos(GeTools.DegreeToRadian(30)), radius * Math.Sin(GeTools.DegreeToRadian(30)));
                    p3 = center.C3D(radius * Math.Cos(GeTools.DegreeToRadian(30)), radius * Math.Sin(GeTools.DegreeToRadian(30)));

                    if (isDrawTriangleTie)
                    {
                        Polyline pl1 = new Polyline() { Closed = true, LayerId = lt["H粗线"] };
                        pl1.AddVertexAt(0, p1.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(1, p2.C2D(), 0, 0, 0);
                        pl1.AddVertexAt(2, p3.C2D(), 0, 0, 0);
                        ext = ext.Add(new Extents2d(pl1.Bounds.Value.MinPoint.C2D(), pl1.Bounds.Value.MaxPoint.C2D()));
                        res.Add(pl1);
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), 15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p1.C2D(), p1.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), 15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");

                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(15 * Math.Cos(GeTools.DegreeToRadian(30)), 15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p2.C2D(), p2.C2D(0, -15), ref ext, "H粗线");

                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(-15 * Math.Cos(GeTools.DegreeToRadian(30)), 15 * Math.Sin(GeTools.DegreeToRadian(30))), ref ext, "H粗线");
                        PLPloter.AddLine(db,p3.C2D(), p3.C2D(0, -15), ref ext, "H粗线");
                    }
                }
                #region 引线
                double width1 = 0, height = 0;
                MText txt1 = TextPloter.GetTextActualWidth(db, T1, scale, out width1, out height, 2.5, Extensions.curFont);

                double width2 = 0;
                MText txt2 = TextPloter.GetTextActualWidth(db, T2, scale, out width2, out height, 2.5, Extensions.curFont);

                double lineWidth = width1 > width2 ? width1 : width2;
                if(T1.Contains("DE"))
                //RebarDimPloter.RebarWire650(db, ref ext, center.C2D(radius * Math.Cos(GeTools.DegreeToRadian(45)), radius * Math.Sin(GeTools.DegreeToRadian(45))), center.C2D(radius * Math.Cos(GeTools.DegreeToRadian(45))+2*scale, radius * Math.Sin(GeTools.DegreeToRadian(45))+5*scale), T1, T2, T3.ToString(), "DE",
                //    GeTools.DegreeToRadian(0), Extensions.curFont, scale);
                //else
                    RebarDimPloter.RebarWire(db, ref ext, center.C2D(radius * Math.Cos(GeTools.DegreeToRadian(45)), radius * Math.Sin(GeTools.DegreeToRadian(45))), T1, T2, T3,
                 GeTools.DegreeToRadian(0), Extensions.curFont, scale);

                // 直径标记
                RebarDimPloter.CreateDiameterMark(db, ref ext, startPoint, eArrow.E_ARROW_DOUBLE_SIDE_ARROW, radius * 2,
                    replaceD, scale, -15);

                if (isDrawTriangleTie)
                {
                    // 支撑架标记
                    double offsetWidth = radius;
                    Point3d p4 = center.C3D(radius / 2 * Math.Cos(GeTools.DegreeToRadian(30)),
                        radius / 2 * Math.Sin(GeTools.DegreeToRadian(30)));

                    // 圆形标记
                    RebarDimPloter.CreateHookLineMark(db, ref ext, p4, "5", offsetWidth, scale);
                }
                // 焊接面
                if (isDrawFaceWeld)
                {
                    RebarDimPloter.CreateFaceWeld(db, ref ext, startPoint.Add(new Vector3d(radius, 0, 0)), radius + 0.5 * scale, scale, replaceDim,"H细线");
                    RebarDimPloter.CreateLeadWireWithoutCircleMark(db, ref ext, startPoint.C3D(radius, -radius), 
                        "单面焊", " ", Extensions.curFont, scale,-4*scale,3*scale);
                }

                #endregion

                foreach (DBObject drawitem in res)
                {
                    recorder.AppendEntity((Entity)drawitem);
                    tr.AddNewlyCreatedDBObject(drawitem, true);
                }

                tr.Commit();
            }
        }

        public List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double,string>>, int, string>> GetRebarList(List<PileRebarPara> pierDisList)
        {
            List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>> tuLst = new List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>>();
            List<Tuple<string, eDB, int, double, string>> rebarLst = new List<Tuple<string, eDB, int, double, string>>();
            Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> tuple;
            double spiralDia0 = 0;
            foreach (PileRebarPara item in pierDisList)
            {
                spiralDia0 = GeneralRebar.outerDiaNew[item.spiral_reinforcement_diameter] * 0.1;
                List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>> tuL = tuLst.FindAll(o => o.Item1.pile_length == item.pile_length);
                if (tuL.Count > 0)
                {
                    int num = tuL[0].Item3 + item.structure_number;
                    tuple = new Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>(item, rebarLst, num, strDiameter);
                }
                else
                {
                    rebarLst = new List<Tuple<string, eDB, int, double, string>>();
                    double topLen = Math.Sqrt(Math.Pow(tH, 2) + Math.Pow(tL, 2));
                    double bottomLen = Math.Sqrt(Math.Pow(bH, 2) + Math.Pow(bL, 2));
                    double len1 = item.pile_length + (bottomLen + topLen - 95);
                    Tuple<string, eDB, int, double, string> tu = new Tuple<string, eDB, int, double, string>("1", item.main_reinforcement_diameter, item.main_reinforcement_number, len1,strMainDiameter);
                    rebarLst.Add(tu);
                    if (pileParameter.is_out_double_layout)
                    {
                        tu = new Tuple<string, eDB, int, double, string>("1a", item.main_reinforcement_diameter, item.main_reinforcement_number, item.out_length, strMainDiameter);
                        rebarLst.Add(tu);
                    }

                    double tSL = GlobalFuncs.GetSpiralLength(item.top_encryption_length, spiralDia0, item.top_encryption_spacing, item.pile_diameter - spiralDia0, item.pier_protect_layer);
                    double mSL = GlobalFuncs.GetSpiralLength(item.middle_encryption_length, spiralDia0, item.middle_encryption_spacing, item.pile_diameter - spiralDia0, item.pier_protect_layer);
                    double bSL = 0;
                    if (item.bottom_encryption_length > 0)
                        bSL = GlobalFuncs.GetSpiralLength(item.bottom_encryption_length - bH, spiralDia0, item.bottom_encryption_spacing, item.pile_diameter - spiralDia0, item.pier_protect_layer);
                  

                    double pBSL = GlobalFuncs.GetSpiralTopLength(spiralDia0, 1, item.pile_diameter, item.pier_protect_layer);
                    double pTSL = GlobalFuncs.GetSpiralTopLength(spiralDia0, 1, item.pile_diameter  - bL * 2, item.pier_protect_layer);
                    double rST = GlobalFuncs.GetSpiraldia(spiralDia0, item.pile_diameter, item.pier_protect_layer);
                    double rSB = GlobalFuncs.GetSpiraldia(spiralDia0, item.pile_diameter - bL * 2, item.pier_protect_layer);
                    double pSL = GlobalFuncs.GetSpiralLength(bH, (rST + rSB) * 0.5, item.bottom_encryption_spacing);
                    double L = (tSL + mSL + bSL + pBSL + pTSL + pSL) + 2 * Math.PI * rST + 20 * spiralDia;
                    tu = new Tuple<string, eDB, int, double, string>("2", item.spiral_reinforcement_diameter, 1, L,strDiameter);
                    rebarLst.Add(tu);

                    double diaT1 = Math.Round((D - item.pier_protect_layer * 2 - spiralDia0) + ((int)item.top_reinforcement_diameter * 0.1 - spiralDia0) * 2, 1);
                    double diaT2 = Math.Round((D - item.pier_protect_layer * 2 - spiralDia0) + ((int)item.top_reinforcement_diameter * 0.1 - spiralDia0) * 2, 1) ;
                    if(tL>0)
                        diaT2 = Math.Round((D - item.pier_protect_layer * 2 - spiralDia0) + ((int)item.top_reinforcement_diameter * 0.1 - spiralDia0) * 2, 1) + tL * 2 - 1;
                    double len3 = Math.Round(Math.PI * (diaT1 + diaT2) * 0.5 + (int)item.top_reinforcement_diameter, 1);
                    N3Len = len3;
                    tu = new Tuple<string, eDB, int, double,string>("3", item.top_reinforcement_diameter, item.top_reinforcement_number, len3, strDiameter);
                    rebarLst.Add(tu);

                    double re = GlobalFuncs.CalculateReduction(item.inner_strengthen_reinforcement_diameter, 90);
                    double dRC = GeneralRebar.outerDiaNew[item.outer_strengthen_reinforcement_diameter];
                    double dRMain = GeneralRebar.outerDiaNew[item.main_reinforcement_diameter];
                    double dia4 = Math.Round((D - item.pier_protect_layer * 2 - spiralDia0 * 2 - dRMain * 0.1 * 2 - dRC * 0.1), 1, MidpointRounding.AwayFromZero);
                    double len4 = Math.Round(Math.PI * dia4 + (int)item.outer_strengthen_reinforcement_diameter, 1);
                    N4 = (int)(item.pile_length / item.outer_strengthen_reinforcement_spacing) + 1;
                    tu = new Tuple<string, eDB, int, double, string>("4", item.outer_strengthen_reinforcement_diameter, N4, len4, strMainDiameter);
                    rebarLst.Add(tu);
                    if (item.inner_strengthen_reinforcement_diameter != eDB.None)
                    {
                        double len5 = Math.Round(Math.Sqrt(3) * dia4 * 0.5, 1) + 2 * GeneralRebar.outerDiaHoke[pileParameter.inner_strengthen_reinforcement_diameter] ;
                        N5Len = len5;
                        if (item.inner_strengthen_reinforcement_num != 6)
                        {
                            tu = new Tuple<string, eDB, int, double, string>("5", item.inner_strengthen_reinforcement_diameter, N4 * 3, len5, strMainDiameter);
                            rebarLst.Add(tu);
                        }
                        else
                        {
                            tu = new Tuple<string, eDB, int, double, string>("5", item.inner_strengthen_reinforcement_diameter, N4 * 6, len5, strMainDiameter);
                            rebarLst.Add(tu);
                        }
                    }
                    //rebarLst.Sort((a, b) => { return a.Item1.CompareTo(b.Item1); });
                    tuple = new Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>(item, rebarLst, item.structure_number, strDiameter);
                }
                tuLst.Add(tuple);
            }
            return tuLst;
        }

        public void RendeDetail(ref Database db, Point2d insertPoint, out Extents2d ext, List<PileRebarPara> pierDisList ,double scale = 50)
        {
            List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string >> tuLst = GetRebarList(pierDisList);
            ext = new Extents2d(insertPoint, insertPoint);
            Point2d CT = insertPoint;
            Point2d M1 = CT.C2D(0, -2 * scale);

            // 绘制表格
            List<string> list = new List<string>();
            list.Add("桩长\\P(cm)");
            list.Add("编号");
            list.Add("直径\\P(mm)");
            //list.Add("大样");
            list.Add("单根长\\P(cm)");
            list.Add("根数");
            list.Add("总长\\P(m)");
            list.Add("单位重\\P(kg/m)");
            list.Add("总重\\P(kg)");
            //list.Add("小计(kg)");
            //double height = 0;
            //double width = 0;
            //ModelTablePloter.DrawCapRebarTable(db, ref ext, M1.C3D(), dt1, list, dt1.Rows.Count + 1, list.Count, ref height, ref width, Extensions.curFont, scale, false);
          
            double height = 0;
            double width = 0;
            bool isChange = false;
            if (tL > 0)
                isChange = true;
            PierModelTablePloter.DrawPileCalTable(db, ref ext, M1.C3D(), list, ref height, ref width, Extensions.curFont, scale, tuLst,isChange);
            double ActualWidth = 0, ActualHeight = 0;
            MText txt = TextPloter.GetTextActualWidth(db, "单根桩基钢筋明细表", scale,out ActualWidth,out ActualHeight, 4);
            TextPloter.AddMText(db,M1.C3D((width - ActualWidth) / 2,ActualHeight + scale * 2), ref ext, "单根桩基钢筋明细表", scale, 4, ActualWidth+2*scale, Extensions.curFont);

            List<string> list1 = new List<string>();
            list1.Add("名称及规格");
            list1.Add("名称及规格");
            list1.Add("单位");
            list1.Add("总重");
            list1.Add("合计");
            double height1 = 0;
            double width1 = 0;
            int numR = 0;
            foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double,string>>, int, string> item in tuLst)
            {
                numR += item.Item1.structure_number;
            }
            txt = TextPloter.GetTextActualWidth(db, "桩基材料数量表(共" + numR + "根)", scale, out ActualWidth, out ActualHeight, 4);
            PierModelTablePloter.DrawCapMaterialsTable(db,  ref ext, M1.C3D(0, -height*1.2 -ActualHeight *4), tuLst, list1, list1.Count, ref height1, ref width1, Extensions.curFont, scale);
            TextPloter.AddMText(db,M1.C3D((width1 - ActualWidth) / 2, -height * 1.2 - ActualHeight * 4 + ActualHeight + scale * 2), ref ext, "桩基材料数量表(共" + numR + "根)", scale, 4, ActualWidth + 2 * scale, Extensions.curFont);

            // 文字
            //string text = "注:";
            //Point3d p1 = M1.C3D( width1 + scale * 5, -height-5* scale - ActualHeight * 3);
            //TextPloter.AddMText(db, p1, ref ext, text, scale, 3,3*scale, Extensions.curFont);
            //3.桩加强N4每隔2米设置一道，N5号筋与N4号筋对应,图中α=h/200。
            string text = @"注
  1.本图尺寸除钢筋直径以毫米计外，余均以厘米为单位。
  2.1号主筋以9m定尺，采用直螺纹钢筋连接器连接。
  3.4号筋每隔2米设置一道，5号筋与4号筋对应。
  4.为确保桩基混凝土浇筑质量，应对每一根桩基进行超声波检测，"+ pileParameter.acoustic_tube_number + "根声测管设于钢筋笼内侧，沿周边等距布置，声测管长度为（桩长+" + (pileParameter.acoustic_tube_length * 0.01).ToString("0.0") + "）m。";
            if (pierDisList[0].pile_type == "嵌岩桩")
            {
                //text += @"\P  5.桩基嵌入中风化变粒岩不少于2倍桩径。
                text += @"\P  5.桩基钢筋构造处理应注意防雷接地预埋要求。";
                if (pileParameter.configure_name.Contains("A"))
                    text += @"\P  6.本图适用于" + pileParameter.pier_name + "桥台桩基，按嵌岩桩设计，嵌入中风化变粒岩不少于2倍桩径";
                else
                    text += @"\P  6.本图适用于" + pileParameter.pier_name + "墩桩基，按嵌岩桩设计，嵌入中风化变粒岩不少于2倍桩径";
            }
            else
            {
                text += @"\P  5.桩基钢筋构造处理应注意防雷接地预埋要求。";
                if (pileParameter.project_type==2)
                {
                    //text += @"\P  6.本图适用于" + pileParameter.pier_name + "桥台桩基，按摩擦桩设计。";

                    if (string.IsNullOrWhiteSpace(pileParameter.pile_name))
                    {
                        text += @"\P  6.柱脚螺栓布置详见钢墩构造图，桩基混凝土浇筑前精确定位预埋。锚固钢板中央开φ700mm孔。";
                        text += @"\P  7.本图适用于" + pileParameter.pier_name + "墩桩基，按摩擦桩设计。";
                    }
                    else
                    {
                        //if (pileParameter.pier_name == "P1")
                        //{
                        //    text += @"\P  6.柱脚螺栓布置详见钢墩构造图，桩基混凝土浇筑前精确定位预埋。锚固钢板中央开φ700mm孔。";
                        //    text += @"\P  7.本图适用于" + pileParameter.pier_name + "墩" + pileParameter.pile_name + "#桩基，按端承桩设计，设计单桩承载力 10053 kN。";
                        //}
                        //else if (pileParameter.pier_name == "P2")
                        //{
                        //    text += @"\P  6.柱脚螺栓布置详见钢墩构造图，桩基混凝土浇筑前精确定位预埋。锚固钢板中央开φ800mm孔。";
                        //    text += @"\P  7.本图适用于" + pileParameter.pier_name + "墩" + pileParameter.pile_name + "#桩基，因缺乏地勘资料，暂按端承桩设计。";
                        //}
                        //else if (pileParameter.pier_name == "P4")
                        //{
                        //    text += @"\P  6.柱脚螺栓布置详见钢墩构造图，桩基混凝土浇筑前精确定位预埋。锚固钢板中央开φ800mm孔。";
                        //    text += @"\P  7.本图适用于" + pileParameter.pier_name + "墩" + pileParameter.pile_name + "#桩基，按摩擦桩设计，设计单桩承载力 6640 KN。";
                        //}
                        //else
                        //{
                            text += @"\P  6.柱脚螺栓布置详见钢墩构造图，桩基混凝土浇筑前精确定位预埋。锚固钢板中央开φ800mm孔。";
                            text += @"\P  7.本图适用于" + pileParameter.pier_name + "墩" + pileParameter.pile_name + "#桩基，因缺乏地勘资料，暂按摩擦桩设计。";
                        //}
                    }
                }
                else
                {
                   
                    if (pileParameter.configure_name.Contains("A"))
                    {
                        text += @"\P  6.本图适用于" + pileParameter.pier_name + "桥台桩基，按摩擦桩设计。";
                    }
                    else
                    {
                        if (string.IsNullOrWhiteSpace(pileParameter.pile_name))
                            text += @"\P  6.本图适用于" + pileParameter.pier_name + "墩桩基，按摩擦桩设计。";
                        else
                            text += @"\P  6.本图适用于" + pileParameter.pier_name + "墩" + pileParameter.pile_name + "#桩基，按摩擦桩设计。";
                    }
                }
                
            }
            Point3d p2 = M1.C3D(width1 + scale * 5, -height * 1.2 - ActualHeight * 3);
            TextPloter.AddMText(db,p2, ref ext, text, scale, 3 ,80*scale, Extensions.curFont);

            try
            {
                BatchInsertQuentity(tuLst);
            }
            catch(Exception ex)
            {

            }
        }


        private void BatchInsertQuentity(List<Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string>> tuLst)
        {
            List<string> sqlList = new List<string>();
            if (tuLst.Count > 0)
            {
                eDB mainDia = tuLst[0].Item1.main_reinforcement_diameter;
                string main_reinforcement_grade = tuLst[0].Item1.main_reinforcement_grade;
                string reinforcement_grade = tuLst[0].Item1.reinforcement_grade;
                string delSql = "delete from busi_engineering_quantity where  bridge_id='"+bridgeId+"' and (portable_belong_part=4 or belong_part=4) ";
                // 数据合并
                Dictionary<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>> dic = new Dictionary<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>>();
                foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
                {
                    List<Tuple<int, Tuple<string, eDB, int, double, string>>> list = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>();
                    for (int i = 0; i < item.Item2.Count; ++i)
                    {
                        eDB strNo = item.Item2[i].Item2;
                        if (dic.Count == 0)
                        {
                            Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                            list.Add(tu);
                            dic.Add(strNo, list);
                        }
                        else
                        {
                            if (!dic.ContainsKey(strNo))
                            {
                                list = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>();
                                Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                                list.Add(tu);
                                dic.Add(strNo, list);
                            }
                            else
                            {
                                List<Tuple<int, Tuple<string, eDB, int, double, string>>> lstDB = new List<Tuple<int, Tuple<string, eDB, int, double, string>>>(); ;
                                dic.TryGetValue(strNo, out lstDB);
                                Tuple<int, Tuple<string, eDB, int, double, string>> tu = new Tuple<int, Tuple<string, eDB, int, double, string>>(item.Item3, item.Item2[i]);
                                lstDB.Add(tu);
                                dic[strNo] = lstDB;
                            }
                        }
                    }
                }
                dic = dic.OrderByDescending(f => f.Key).ToDictionary(f => f.Key, f => f.Value);
                string remark = "桩基钢筋";
                string material = "钢筋";
                string materialCode = main_reinforcement_grade;
                string materielSpecs = mainDia.ToString();
                foreach (KeyValuePair<eDB, List<Tuple<int, Tuple<string, eDB, int, double, string>>>> pr in dic)
                {
                    string strNo = "钢筋";
                    string unit = "kg";
                    eDB diameter = eDB.None;
                    double totallength = 0;
                    //double totalnum = 0;
                    //double length = 0;
                    // 设置表数据

                    for (int i = 0; i < pr.Value.Count; ++i)
                    {
                        // 钢筋编号
                        diameter = pr.Key;                         // 直径
                        totallength += pr.Value[i].Item1 * (pr.Value[i].Item2.Item3 * pr.Value[i].Item2.Item4);
                        //length = pr.Value[i].Item2.Item4;
                        //totalnum += pr.Value[i].Item1 * (pr.Value[i].Item2.Item3);
                    }
                    remark = "桩基钢筋";
                    material = "钢筋";
                    materialCode = main_reinforcement_grade;
                    materielSpecs = diameter.ToString();
                    if (diameter == mainDia)
                    {
                        materialCode = main_reinforcement_grade;
                    }
                    else
                        materialCode = reinforcement_grade;
                    double weight = GlobalFuncs.GetUnitWeight(diameter);
                    double totalWeight = totallength * 0.01 * weight;

                    string id = Guid.NewGuid().ToString();
                    string sql = "insert into busi_engineering_quantity(id,bridge_id,materiel,materiel_code,materiel_specs,unit,"
                        + "unit_weight,total_weight,is_auto,belong_part,portable_belong_part,remark)"
                        + "values('" + id + "','" + bridgeId + "','" + material + "','" + materialCode + "','" + materielSpecs + "','kg','"
                        + weight + "','" + totalWeight  + "','2','4','4','" + remark + "')";
                    sqlList.Add(sql);
                }


                #region 其它(混凝土、钢筋连接器、声测管
                double volumnAll = 0; //混凝土体积
                int totalCap = 0; //钢筋连接器数量
                double weightTubee = 0; //声测管重量
                foreach (Tuple<PileRebarPara, List<Tuple<string, eDB, int, double, string>>, int, string> item in tuLst)
                {
                    double volumn = Math.Ceiling(item.Item1.pile_length * 0.01 * Math.PI * item.Item1.pile_diameter * 0.5 * 0.01 * item.Item1.pile_diameter * 0.5 * 0.01);
                    volumnAll += volumn * item.Item3;
                    totalCap += ((int)(item.Item1.pile_length * 0.01 / 9)) * item.Item1.main_reinforcement_number * item.Item3;
                    string tubetype = item.Item1.acoustic_tube_type;
                    double outDia = double.Parse(tubetype.Split('*')[0]);
                    double thinessDia = double.Parse(tubetype.Split('*')[1]);
                    weightTubee += 0.02466 * thinessDia * (outDia - thinessDia) * (item.Item1.pile_length * 0.01 + item.Item1.acoustic_tube_length * 0.01) * item.Item1.acoustic_tube_number * item.Item1.structure_number;
                }
                material = "混凝土";
                materialCode = material;
                materielSpecs = tuLst[0].Item1.concrete_no;
                remark = "桩基混凝土";
                string id1 = Guid.NewGuid().ToString();
                string sqlIn = "insert into busi_engineering_quantity(id,bridge_id,materiel,materiel_code,materiel_specs,unit,"
                    + "total_weight,is_auto,belong_part,portable_belong_part,remark)"
                    + "values('" + id1 + "','" + bridgeId + "','" + material + "','" + materialCode + "','" + materielSpecs + "','m3','"
                    + volumnAll + "','2','4','4','" + remark + "')";
                sqlList.Add(sqlIn);

                material = "钢筋连接器";
                materialCode = material;
                materielSpecs = mainDia.ToString();
                remark = "桩基钢筋连接器";
                id1 = Guid.NewGuid().ToString();
                sqlIn = "insert into busi_engineering_quantity(id,bridge_id,materiel,materiel_code,materiel_specs,unit,"
                    + "total_weight,is_auto,belong_part,portable_belong_part,remark)"
                    + "values('" + id1 + "','" + bridgeId + "','" + material + "','" + materialCode + "','" + materielSpecs + "','个','"
                    + totalCap + "','2','4','4','" + remark + "')";
                sqlList.Add(sqlIn);

                material = "声测管";
                materialCode = material;
                materielSpecs = "Φ"+ tuLst[0].Item1.acoustic_tube_type.Replace("*", "×");
                remark = "桩基声测管";
                id1 = Guid.NewGuid().ToString();
                sqlIn = "insert into busi_engineering_quantity(id,bridge_id,materiel,materiel_code,materiel_specs,unit,"
                    + "total_weight,is_auto,belong_part,portable_belong_part,remark)"
                    + "values('" + id1 + "','" + bridgeId + "','" + material + "','" + materialCode + "','" + materielSpecs + "','kg','"
                    + weightTubee + "','2','4','4','" + remark + "')";
                sqlList.Add(sqlIn);

                if(sqlList.Count>0)
                {
                    MySqlHelper.ExecuteNonQuery(delSql, System.Data.CommandType.Text);
                    MySqlHelper.ExecuteNonQuery(sqlList);
                }
                #endregion
            }
        }


       
    }



}
